﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SmartText
{
    /// <summary>
    /// Interaction logic for OptionWindow.xaml
    /// </summary>
    public partial class OptionWindow : Window
    {
        private AppInfo _info;
        public AppInfo Info { get; set; }

        public OptionWindow(AppInfo info)
        {
            InitializeComponent();
            var sortedEi = from ei in Encoding.GetEncodings() orderby ei.DisplayName ascending select ei.GetEncoding();
            cboTemplateEnc.ItemsSource = sortedEi;
            cboParamEnc.ItemsSource = sortedEi;
            cboOutputEnc.ItemsSource = sortedEi;
            cboLang.ItemsSource = ((App)Application.Current).LanguageList;

            Info = new AppInfo();
            Info.TemplateEncoding = info.TemplateEncoding;
            Info.ParamEncoding = info.ParamEncoding;
            Info.OutputEncoding = info.OutputEncoding;
            Info.LangInfo = info.LangInfo;
            grd.DataContext = Info;

            _info = info;
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (Info.LangInfo.Lang != _info.LangInfo.Lang &&　App.LoadLanguage(Info.LangInfo.Lang))
            {
                _info.LangInfo = Info.LangInfo;
            }
            _info.TemplateEncoding = Info.TemplateEncoding;
            _info.ParamEncoding = Info.ParamEncoding;
            _info.OutputEncoding = Info.OutputEncoding;
            this.Close();
        }
    }
}
